package de.szut.util;

/**
 * Utility class for generating random results
 * @author Marc Huisinga
 *
 */
public final class Randomizer implements Immutable {
	
	/**
	 * Generates true by the chance passed as parameter.
	 * @param percentage - chance
	 * @return result
	 */
	public boolean randomize(double percentage) {
		if (new RangeChecker(0, 1).isInRangeInclusive(percentage)) {
			return Math.random() < percentage;
		} else {
			throw new IllegalArgumentException("Percentage has to be between 0 and 1.");
		}
	}
	
	/**
	 * Generates a random value within the specified range.
	 * @param min - Inclusive lower bound
	 * @param max - Exclusive upper bound
	 * @return generated random value
	 */
	public double randomizeValue(double min, double max) {
		return min + Math.random() * (max - min);
	}
}
